<?php
namespace app\adminbackstage\controller;
/*
 * 赏金流水
 */
use think\facade\Request;

use app\adminbackstage\model\UserAmountRewardDetailed;
/**
 * Description of Index
 *
 * @author asus80
 */
class UserAmountRewardDetailedController {
    //put your code here
    public function userAmountRewardDetailedList(){
        
        $page = Request::param('page');
        $num = Request::param('num');

        $start = Request::param('start');
        $end = Request::param('end');
        $phone = Request::param('phone');
        
        $type = Request::param('type');//状态
        $state = Request::param('state');
        
        $u_type = Request::param('u_type');//用户类型
        $remarks = Request::param('remarks');
//        $a_id = Request::param('pro_num');//活动编号
//        
//        $detailed = new Detailed();
//        $where = []; 

//        $where[] = ['d.id','>=',5912948];
        $where[] = ['d.uid','>',0];
        //$where[] = ['u.enable','=',1];
        if(!empty($start)){
            $time_start = strtotime($start);
            $where[] = ['d.addtime','>=',$time_start];
        }
        
        if(!empty($end)){
            $time_end = strtotime($end)+(24*3600-1);
            $where[] = ['d.addtime','<',$time_end];
        }
        
        if(!empty($phone)){
            
            $where[] = ['u.phone','=',$phone];
        }
        
        if(!empty($type)){

            $where[] = ['d.type','=',$type];
        }
        
//        if(!empty($a_id)){
//
//            $where[] = ['d.a_id','=',$a_id];
//        }
        
        if(!empty($u_type)){
            $where[] = ['u.type','=',$u_type];
        }
        
        if(!empty($remarks)){
            $where[] = ['d.remarks','like','%'.$remarks.'%'];
        }

        if(!empty($state)){
            if($state == -1){
                $state = 0;
            }
            $where[] = ['d.state','=',$state];
        }
        $listinfo = UserAmountRewardDetailed::listUserAmountRewardDetailed($page,$num,$where);
        $count = UserAmountRewardDetailed::countUserAmountRewardDetailed($where); 


        foreach ($listinfo as $key => $value) {
            if ($value['type']=='1') {
                $listinfo[$key]['type'] = '下级下单奖励';
            }elseif($value['type']=='2'){
                $listinfo[$key]['type'] = '';
            }elseif($value['type']=='3'){
                $listinfo[$key]['type'] = '邀请奖励';
            }else{
                $listinfo[$key]['type'] = '其他';
            }
            
            
            if ($value['state']==1) {
                $listinfo[$key]['state_str'] = '平台收入';
            }
            elseif($value['state']==2){
                $listinfo[$key]['state_str'] = '平台支出';
            }
//            elseif ($value['state']==3) {
//                $listinfo[$key]['state_str'] = '冻结';
//            }
//            elseif ($value['state']==4) {
//                $listinfo[$key]['state_str'] = '解冻';
//            }
//            elseif ($value['state']==0) {
//                $listinfo[$key]['state_str'] = '不变';
//            }
            
            /*if($value['u_type'] == 2){
                $listinfo[$key]['u_type'] = '商家用户';
            }
            else{
                $listinfo[$key]['u_type'] = '买家用户';
            }*/
            
//            $listinfo[$key]['time'] = date( "Y-m-d H:i:s",$value['addtime']); 
            $listinfo[$key]['addtime'] = date( "Y-m-d H:i:s",$value['addtime']); 
        }
        
//        $list = '<ul>'.$top.$tail.'</ul>';
//        $return = array($listinfo,$list);
//        
//        echo json_encode($return);
        return json(['code' => 1, 'msg' => lang(''), 'data' => $listinfo, 'count' => $count]);
    }
}
